package com.kotlin.usercenter.presenter

import com.kotlin.base.ext.excute
import com.kotlin.base.presenter.BasePresenter
import com.kotlin.base.rx.BaseSubscriber
import com.kotlin.usercenter.presenter.view.RegisterView
import com.kotlin.usercenter.service.UserService
import javax.inject.Inject
import javax.inject.Named

class RegisterPresenter @Inject constructor() : BasePresenter<RegisterView>() {
    //    @Named("service")  Java编码中使用
    @Inject
    @field:[Named("service")]  // kotlin编码中使用
    lateinit var userService: UserService

    @Inject
    @field:[Named("service2")]  // kotlin编码中使用
    lateinit var userService2: UserService

    fun register(mobile: String, verifyCode: String, pwd: String) {
        /**
         * 业务逻辑
         * */
        if (!checkNetWork()) {
            return
        }
        mView.showLoading()
        userService.register(mobile, verifyCode, pwd)
                .excute(object : BaseSubscriber<Boolean>(mView) {
                    override fun onNext(t: Boolean) {
                        if (t){
                            mView.registerResult("注册成功")
                        }
                    }
                },lifecycleProvider)
    }

    fun register2(mobile: String, verifyCode: String, pwd: String) {
        /**
         * 业务逻辑
         * */
        if (!checkNetWork()) {
            return
        }
        mView.showLoading()
        userService2.register(mobile, verifyCode, pwd)
                .excute(object : BaseSubscriber<Boolean>(mView) {
                    override fun onNext(t: Boolean) {
                        if (t){
                            mView.registerResult("注册成功")
                        }
                    }
                },lifecycleProvider)
    }
}